package band.wukong.practice.javase.core.thread.basic;

/**
 * Desc: 多个线程共享同一个对象的实例变量
 * Author: sunjs
 * Date: 2009-11-5 9:47:45
 */
public class Demo03 extends Thread {
    private int a = 0;

    public void run() {
        for (int i = 0; i < 10; i++) {
            a++;
            String threadName = currentThread().getName();
            if (threadName.equals("main")) {
                System.out.println(threadName + ":" + a);
            } else if (threadName.equals("Thread-0")) {
                System.out.println(threadName + ":" + a);
            } else if (threadName.equals("Thread-1")) {
                System.out.println(threadName + ":" + a);
            } else if (threadName.equals("Thread-2")) {
                System.out.println(threadName + ":" + a);
            }
            try {
                sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) {
        Demo03 machine1 = new Demo03();
        Demo03 machine2 = new Demo03();
        Demo03 machine3 = new Demo03();
        machine1.start();
        machine1.run();
        machine2.start();
        machine3.start();
    }
}
